package com.tancire.web.controller.platform.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.system.domain.SysApp;
import com.tancire.system.service.ISysAppService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 应用管理Controller
 *
 * @author tancire
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/sysApp")
public class SysAppController extends BaseController {
    @Resource
    private ISysAppService sysAppService;

    /**
     * 查询应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysApp sysApp) {
        startPage();
        List<SysApp> list = sysAppService.selectSysAppList(sysApp);
        return getDataTable(list);
    }

    /**
     * 导出应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:export')")
    @Log(title = "应用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysApp sysApp) {
        List<SysApp> list = sysAppService.selectSysAppList(sysApp);
        ExcelUtil<SysApp> util = new ExcelUtil<SysApp>(SysApp.class);
        util.exportExcel(response, list, "应用管理数据");
    }

    /**
     * 获取应用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId) {
        return AjaxResult.success(sysAppService.selectSysAppByAppId(appId));
    }

    /**
     * 新增应用管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:add')")
    @Log(title = "应用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysApp sysApp) {
        return toAjax(sysAppService.insertSysApp(sysApp));
    }

    /**
     * 修改应用管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:edit')")
    @Log(title = "应用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysApp sysApp) {
        return toAjax(sysAppService.updateSysApp(sysApp));
    }

    /**
     * 删除应用管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysApp:remove')")
    @Log(title = "应用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds) {
        return toAjax(sysAppService.deleteSysAppByAppIds(appIds));
    }
}
